// 云函数入口文件
const cloud = require('wx-server-sdk')
var rp = require('request-promise');
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database({
  env: cloud.DYNAMIC_CURRENT_ENV
});
//授权腾讯云
const tcp = function (ACCESS_TOKEN,EXPRESS_TIME){
  let options = {
    method: 'POST',
    uri: "https://api.weixin.qq.com/tcb/getqcloudtoken?access_token=ACCESS_TOKEN",
    body: {
      access_token: ACCESS_TOKEN,
      lifespan: EXPRESS_TIME
    },
    json: true
  };
  rp(options).then(function(res){
    console.log(res, '----res')
    return res
  }).catch(function (err) {
    console.log(err)
  });
};
// 云函数入口函数
exports.main = async (event, context) => {
  let { token, timeStr} = event;
  try {
    let data = await tcp(token, timeStr);
    console.log(data, '----data')
    return data
    
  } catch (err) {
    return err
  }

}